package com.xjrsoft.module.oa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjrsoft.module.oa.entity.XjrOaFilefolder;
import com.xjrsoft.module.oa.mapper.XjrOaFilefolderMapper;
import com.xjrsoft.module.oa.service.IXjrOaFilefolderService;
import com.xjrsoft.module.oa.service.IXjrOafileinfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 文件夹表 服务实现类
 * </p>
 *
 * @author zwq
 * @since 2021-04-20
 */
@Service
public class XjrOaFilefolderServiceImpl extends ServiceImpl<XjrOaFilefolderMapper, XjrOaFilefolder> implements IXjrOaFilefolderService {

    @Autowired
    private IXjrOafileinfoService iXjrOafileinfoService;

    @Autowired
    private XjrOaFilefolderMapper xjrOaFilefolderMapper;
    

    @Override
    public List<XjrOaFilefolder> query(String keywords, Integer fileType,Integer isRoot) {
        if(fileType==1 || fileType==2) {
            return null;
        }
        LambdaQueryWrapper<XjrOaFilefolder> folderQueryWrapper = Wrappers.<XjrOaFilefolder>query().lambda().eq(XjrOaFilefolder::getDeleteMark, 0);
        if(!StringUtils.isEmpty(keywords)){
            folderQueryWrapper.like(XjrOaFilefolder::getFolderName, keywords);
        }
        //是否为根目录
        if(isRoot==1){
           folderQueryWrapper.eq(XjrOaFilefolder::getParentId,"0");
        }
        if (fileType==0) {
            folderQueryWrapper.eq(XjrOaFilefolder::getEnabledMark,1);
        }else if (fileType==3) {
            // 回收站里的文件夹
            folderQueryWrapper.eq(XjrOaFilefolder::getEnabledMark,0);
        } else if (fileType==4) {
            // 我的共享文件夹
            folderQueryWrapper.eq(XjrOaFilefolder::getIsShare, 1).eq(XjrOaFilefolder::getEnabledMark,1);
        } else if (fileType==5) {
            // 他人共享文件夹
            folderQueryWrapper.eq(XjrOaFilefolder::getIsShare, 1).eq(XjrOaFilefolder::getEnabledMark,1);
        }
        return this.list(folderQueryWrapper);

    }


    @Override
    public  List<XjrOaFilefolder>  getSonFolder(String folderId,Integer isEnabledMark) {
        LambdaQueryWrapper<XjrOaFilefolder> fileinfoQueryWrapper = Wrappers.<XjrOaFilefolder>query().lambda().eq(XjrOaFilefolder::getDeleteMark, 0).eq(XjrOaFilefolder::getEnabledMark,isEnabledMark).eq(XjrOaFilefolder::getParentId,folderId);
        return this.list(fileinfoQueryWrapper);
    }
}
